package com.hgm.travelapp.activity

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.CountDownTimer
import android.view.Window
import android.view.WindowManager
import androidx.viewbinding.ViewBinding
import com.hgm.travelapp.R
import com.hgm.travelapp.databinding.ActivityWelcomeBinding
import com.hgm.travelapp.utils.ToastUtil

class WelcomeActivity : AppCompatActivity() {

      private var timer: CountDownTimer? = null

      private val mBinding: ActivityWelcomeBinding by lazy {
            ActivityWelcomeBinding.inflate(layoutInflater)
      }

      override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            //隐藏状态栏
            requestWindowFeature(Window.FEATURE_NO_TITLE)
            window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
            setContentView(mBinding.root)

            //启动开启倒计时
            countDownTimer()
            //点击跳过，进入登录页
            mBinding.btnJump.setOnClickListener {
                  timer?.cancel()
                  startActivity(Intent(this@WelcomeActivity, LoginActivity::class.java))
                  this.finish()
            }
      }

      /**
       * 倒计时
       */
      private fun countDownTimer() {
            timer = object : CountDownTimer(4000, 1000) {
                  override fun onTick(millisUntilFinished: Long) {
                        var time = millisUntilFinished / 1000
                        mBinding.btnJump.text = "$time 跳过"
                  }

                  override fun onFinish() {
                        startActivity(Intent(this@WelcomeActivity, LoginActivity::class.java))
                  }
            }
            timer?.start()
      }


      override fun onDestroy() {
            super.onDestroy()
            //销毁时取消倒计时
            timer?.cancel()
      }


}